<template>
    <div>

    </div>
</template>

<script>
    import { mapMutations } from 'vuex'
    export default {
        name: "wx",
        data() {
            return {
                code: '',
                href: ''
            }
        },
        created() {
          this.validateUser();

            // let arr = location.href.split('/');
            // let uri = encodeURI(`${arr[0]}//${arr[2]}/wx`);
            // this.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + this.appId + '&redirect_uri=' + uri + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechart_redirect';
            // this.code = this.$route.query.code;

            // if (!this.code) {
            //     window.location.replace(this.href);
            // } else {
            //     this.validateUser();
            // }
        },
        methods: {
            ...mapMutations(['SET_WX_INFO']),
            async validateUser() {
                const res = await this.$http.get('/common/mp/user/register', {params: {code: this.code}});
                localStorage.setItem('wxInfo', JSON.stringify(res.data));
                //window.location.replace(`${location.origin}/home`);
                this.SET_WX_INFO(res.data);
                this.$router.replace('/home');
            }
        }
    }
</script>
